package cn.com.nwpu.visual_system.controller;

import cn.com.nwpu.visual_system.entity.ModelPredictData;
import cn.com.nwpu.visual_system.service.ModelService;
import cn.com.nwpu.visual_system.utils.Response;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Hutengzhong
 * @version 1.0.0
 * @title ModelController
 * @description TODO 与模型训练和预测的相关请求
 * @date 2024/5/18 16:20
 */
@RestController
@RequestMapping("model")
public class ModelController {
    @Autowired
    ModelService modelService;

    @PostMapping("trainModel")
    public Response trainModel() {
        modelService.trainModel();
        Response response = new Response(200, "训练完成", true);
        return response;
    }

    @PostMapping("predictModel")
    public Response predictModel() {
        ModelPredictData mpd = modelService.predictModel();
        Map<String, List<Object>> resultMap = modelService.getPredictMap();
        Map<String, String> standard = modelService.getStandard();
        HashMap<String, Object> returnMap = new HashMap<>();
        returnMap.put("standard", standard);
        returnMap.put("predicts", resultMap);
        Response response = new Response(200, "预测完成", true);
        response.setData(returnMap);
        return response;
    }
}
